<?php 
namespace app\user\model;

use think\Model;

class User extends Model
{

    protected $type = [
            'ext'    =>  'json',
        ];

    public function group()
    {
        return $this->belongsToMany('Group',\think\Config::get('database.prefix').'auth_access','group_id','uid');
    }
    public function comment()
    {
        return $this->hasMany('\\app\\content\\model\\Comment','uid','id');
    }

    public function setEmailAttr($value)
    {
        return strtolower($value);
    }
    public function setPasswordAttr($value,$data)
    {
        if ($value) {
            return crypt_pwd($value,$data['email'] . ' love ebcms forever!');
        }
    }
    public function setSaltAttr($value,$data)
    {
        if (!$value && $data['password']) {
            return $data['email'] . ' love ebcms forever!';
        }
    }
    public function getSpaceAttr($value,$data)
    {
        return url('user/space/index?id='.$data['id']);
    }
}